package com.hkp.demo.controller;

import com.hkp.demo.entity.response.AjaxResponseWrapper;
import com.hkp.demo.entity.vo.*;
import com.hkp.demo.service.IAuditResultService;
import com.hkp.demo.service.IProjectService;
import com.hkp.demo.service.IRuleService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author HuKangPing
 */
@RestController
@Api(tags = "质量报告")
@RequestMapping("/dq/report")
@Slf4j
public class QualityReportVOController {

    @Resource
    private IProjectService iProjectService;

    @Resource
    private IAuditResultService iAuditResultService;

    @Resource
    private IRuleService iRuleService;

    /**
     * 质量报告详情
     *
     * @param day (YYYY-MM-DD 格式) 当天
     * @return
     */
    @GetMapping("/queryQualityReport")
    public AjaxResponseWrapper<QualityReportVO> getDimensionGroupVOList(String day) {
        try {
//            专项数
            Long projectCount = iProjectService.getProjectNum(day);
//            规则数
            Long ruleCount = iRuleService.getRuleNum(day);
//            查询当天稽核总次数
            Long checkCount = iAuditResultService.getCurrentDayAuditNum(day, null);
//            result为2 ==> 警告数 3==> 严重数
            Long alertCount = iAuditResultService.getCurrentDayAuditNum(day, "2");
            Long severeCount = iAuditResultService.getCurrentDayAuditNum(day, "3");
            TotalDataQualityVO totalDataQualityVO = new TotalDataQualityVO(projectCount, ruleCount, checkCount, severeCount, alertCount);
            List<DimensionGroupVO> dimensionGroupVOList = iAuditResultService.getDimensionGroupVO(day);
            List<ProjectDetailsGroupVO> ruleAndCounts = iProjectService.getRuleAndCounts(day);
//            获取resultDayGroupVOS
            List<ResultDayGroupVO> resultDayGroupVOS = iAuditResultService.getResultDayGroupVO(day);
            List<RuleQualityVO> ruleQualityVOS = iAuditResultService.getRuleQualityVO(day);
            QualityReportVO qualityReportVO = new QualityReportVO(totalDataQualityVO, dimensionGroupVOList, ruleAndCounts, resultDayGroupVOS, ruleQualityVOS);
            return AjaxResponseWrapper.operate(true, null, qualityReportVO);
        } catch (Exception e) {
            log.error("查询维度名称和对应维度警告数失败");
            e.printStackTrace();
            return AjaxResponseWrapper.fail(e);
        }
    }

    /**
     * 查看月份内是否有执行记录，(月份：YYYY-MM 格式)
     *
     * @param month
     * @return
     */
    @GetMapping("/listExecCalendar")
    public AjaxResponseWrapper<List<String>> getListExecCalendar(String month) {
        try {
            return AjaxResponseWrapper.operate(true, null, iAuditResultService.getListExecCalendar(month));
        } catch (Exception e) {
            log.error("查询月份内是否有执行记录失败");
            e.printStackTrace();
            return AjaxResponseWrapper.fail(e);
        }
    }
}
